This article mainly introduces the function of variable parameter, then analyzes its principle, how the programmer realizes and encapsulates them, and finally it is possible problems and avoid measures.VA functions (variable argument function), the
Variable parameter lists can be implemented with macros defined in the Stdarg.h header file, which is part of the standard library. This header file declares a type va_list and three macros----Va_start,va_arg,va_end. You can declare a variable of
The best example of variable-length argument lists function is printf ()
The proper declaration for printf () is
Int printf (char * format ,...)
Where the declaration... means that the number and types of these arguments may vary. The
The principle of transfer of function parametersfunction parameters are accessed in memory in the form of stacks, from right to left into the stack.The parameter stores the format in memory:In the process, the stack address is allocated from high to
0 Introduction 1, Course Syllabus 2, Part two lesson six: Creating your own Variable Type 3, part two, seventh trailer: Document Reading and writing course outline our courses are divided into four parts, each of which will have exercises at the end
In/*java, the parameter list is not fixed, but the parameter type is the same, and when used, the formal parameter variable is the reference of the array type */public class Appenter{public static void Main (string[] args) Throws
How to use variable argument function
C supports the VA function. c ++ supports the VA function as an extension of C. It is not recommended in C ++, the polymorphism introduced by C ++ can also implement functions with variable parameter numbers.
Self is useful for distinguishing between global variables/functions and member variables/functions in objects. For example, it provides a scoping mechanism that I personally think is much clearer than Ruby's @ and @@ 清晰 which may be a habit, but it'
Formal parameters: All called "formal arguments" are parameters that are used when defining function names and body functions to receive the arguments passed when the function is called. The function of formal parameters is to realize the relation
Difference between parameter and argument reproduced from: http://smilejay.com/2011/11/parameter_argument/
When I write a comment on a function, I am considering whether to use parameter or argument to describe its parameters.According to some
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.